<template>
  <div>
    <p class="navigation">
      <span class="xiangmu" @click="historyGo">项目核算</span>
      > <span>{{ projectNamess1 }}</span>
    </p>
    <div style="margin-bottom: 20px">
      <el-date-picker
        v-model="month"
        type="month"
        placeholder="选择月"
        :clearable="false"
        value-format="yyyy-MM"
        @change="changeMonth"
      >
      </el-date-picker>
      <el-select
        v-model="fids"
        placeholder="请选择职能组"
        @change="changeGroup"
        clearable
      >
        <el-option
          v-for="item in groupsList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
      <el-select
        v-model="projectNamess1"
        placeholder="请选择项目名称"
        @change="changeProject"
      >
        <el-option
          style="font-weight: 400"
          v-for="item in projectList"
          :key="item.id"
          :label="item.name"
          :value="item"
        >
        </el-option>
      </el-select>
      <el-button
        type="success"
        @click="exportExcel()"
        plain="plain"
        class="exit"
        >导出</el-button
      >
    </div>

    <div class="allPrjHours">所有项目月度总工时：{{ allPrjHours }}</div>
    <div class="outlayTotal">
      财务费用总额：
      <el-input
        style="width: 50%"
        placeholder="请输入"
        v-model="outlayTotal"
        oninput="value=value.replace(/[^\d.]/g,'')"
        @change="inputChange"
      >
      </el-input>
      元
    </div>
    <div class="dimOtherCostTotal">
      不明确费用总额：
      <el-input
        style="width: 50%"
        placeholder="请输入"
        v-model="dimOtherCostTotal"
        oninput="value=value.replace(/[^\d.]/g,'')"
        @change="inputChange"
      >
      </el-input>
      元
    </div>
    <!-- 表格 -->
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      ref="planTable"
      show-summary
      :summary-method="getSummaries"
    >
      <el-table-column
        type="index"
        align="center"
        label="序号"
        width="50"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="groupName"
        align="center"
        label="职能组"
        width="120"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="userName"
        align="center"
        label="姓名"
        width="100"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="monthHour"
        align="center"
        label="本月工时"
        width="100"
        id="exportTable"
      >
      </el-table-column>
      <!-- <el-table-column prop="totalHour" align="center" label="所有项目月度总工时" width="100" id="exportTable">
            </el-table-column> -->
      <el-table-column
        prop="totalHour"
        align="center"
        label="月度总工时"
        width="100"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="salary"
        align="center"
        label="工资"
        width="100"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="socialInsurance"
        align="center"
        label="社保"
        width="100"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="outlay"
        align="center"
        label="财务费用均摊"
        width="120"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="otherCostList"
        align="center"
        label="明确的其他费用"
        id="exportTable"
        :formatter="convertArr1"
      >
      </el-table-column>
      <el-table-column
        prop="dimOtherCosts"
        align="center"
        label="不明确费用均摊"
        id="exportTable"
        :formatter="convertArr2"
      >
      </el-table-column>
      <el-table-column
        width="120"
        prop="total"
        align="center"
        label="当月核算结果"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        width="120"
        prop="totalYear"
        align="center"
        label="累计核算结果"
        id="exportTable"
      >
      </el-table-column>
      <el-table-column
        prop="id"
        align="center"
        label="操作"
        width="120"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.otherCost == null ? true : false"
            type="primary"
            plain
            size="mini"
            @click="addFee(scope.row)"
            >添加费用</el-button
          >
          <el-button
            v-else
            type="primary"
            plain
            size="mini"
            @click="upDateFee(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加费用和编辑费用的对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogFormPlan"
      center
      width="40%"
      :close-on-click-modal="false"
    >
      <div v-if="this.category == 'add'">
        <el-form :model="form" ref="acctForm" :rules="form.rules">
          <el-form-item
            label="工资"
            :label-width="formLabelWidth"
            prop="salary"
            :rules="{
              required: true,
              message: '请输入工资金额',
              trigger: 'blur',
            }"
          >
            <el-input
              type="number"
              v-model="form.salary"
              autocomplete="off"
              @input="inputnum1"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="社保"
            :label-width="formLabelWidth"
            prop="socialInsurance"
            :rules="{
              required: true,
              message: '请输入社保金额',
              trigger: 'blur',
            }"
          >
            <el-input
              type="number"
              v-model="form.socialInsurance"
              autocomplete="off"
              @input="inputnum2"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="财务费用" :label-width="formLabelWidth" prop="outlay" :rules="{
                        required: true,
                        message: '请输入财务费用',
                        trigger: 'blur',
                    }">
                        <el-input type="number" v-model="form.outlay" autocomplete="off" @input="inputnum3"></el-input>
                    </el-form-item> -->
          <el-form-item
            v-for="(other, index) in form.otherCostList"
            :key="other.key"
            :label="`明确的其他费用${index + 1}`"
            :prop="'otherCostList.' + index + '.value'"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="other.name"
              autocomplete="off"
              style="width: 20%"
            ></el-input
            >:
            <el-input
              type="number"
              v-model="other.value"
              autocomplete="off"
              style="width: 20%"
              @blur="inputBlur(other.value, index)"
            ></el-input
            >元
            <el-button icon="el-icon-plus" circle @click="add1"></el-button>
            <el-button
              v-show="index > 0"
              icon="el-icon-minus"
              circle
              @click.prevent="dele1(other)"
            ></el-button>
          </el-form-item>
          <!-- <el-form-item v-for="(other, index) in form.dimOtherCostList" :key="other.key"
                        :label="`不明确的其他费用${index + 1}`" :prop="'dimOtherCostList.' + index + '.value'"
                        :label-width="formLabelWidth">
                        <el-input v-model="other.name" autocomplete="off" style="width: 20%"></el-input>:
                        <el-input type="number" v-model="other.value" autocomplete="off" style="width: 20%"
                            @blur="inputBlur2(other.value, index)"></el-input>元
                        <el-button icon="el-icon-plus" circle @click="add2"></el-button>
                        <el-button v-show="index > 0" icon="el-icon-minus" circle @click.prevent="dele2(other)"></el-button>
                    </el-form-item> -->
        </el-form>
      </div>
      <div v-if="this.category == 'update'">
        <el-form :model="form" ref="acctForm" :rules="form.rules">
          <el-form-item
            label="工资"
            :label-width="formLabelWidth"
            prop="salaryLog"
          >
            <el-input
              type="number"
              v-model="form.salaryLog"
              autocomplete="off"
              @input="inputnum1"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="社保"
            :label-width="formLabelWidth"
            prop="socialInsuranceLog"
          >
            <el-input
              type="number"
              v-model="form.socialInsuranceLog"
              autocomplete="off"
              @input="inputnum2"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="财务费用" :label-width="formLabelWidth" prop="outlayLog">
                        <el-input type="number" v-model="form.outlayLog" autocomplete="off" @input="inputnum3"></el-input>
                    </el-form-item> -->
          <el-form-item
            v-for="(other, index) in form.otherCostList"
            :key="other.key"
            :label="`明确的其他费用${index + 1}`"
            :prop="'otherCostList.' + index + '.value'"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="other.name"
              autocomplete="off"
              style="width: 20%"
            ></el-input
            >:
            <el-input
              type="number"
              v-model="other.value"
              autocomplete="off"
              style="width: 20%"
              @input="inputBlur(other.value, index)"
            ></el-input
            >元
            <el-button icon="el-icon-plus" circle @click="add1"></el-button>
            <el-button
              v-show="index > 0"
              icon="el-icon-minus"
              circle
              @click.prevent="dele1(other)"
            ></el-button>
          </el-form-item>
          <!-- <el-form-item v-for="(other, index) in form.dimOtherCostList" :key="other.key"
                        :label="`不明确的其他费用${index + 1}`" :prop="'dimOtherCostList.' + index + '.value'"
                        :label-width="formLabelWidth">
                        <el-input v-model="other.name" autocomplete="off" style="width: 20%"></el-input>:
                        <el-input type="number" v-model="other.value" autocomplete="off" style="width: 20%"
                            @input="inputBlur2(other.value, index)"></el-input>元
                        <el-button icon="el-icon-plus" circle @click="add2"></el-button>
                        <el-button v-show="index > 0" icon="el-icon-minus" circle @click.prevent="dele2(other)"></el-button>
                    </el-form-item> -->
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel()">取 消</el-button>
        <el-button
          v-if="this.category == 'add'"
          type="primary"
          @click="submit('acctForm')"
          >确 定</el-button
        >
        <el-button
          v-if="this.category == 'update'"
          type="primary"
          @click="submitUpdate('acctForm')"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  projectAccounting,
  selectProjectListByReq,
  saveCostInfo,
  updateCostInfo,
  exportEmpInfo,
  projectWholeCount,
} from "@/service/financeApi.js"; //接口
import { selectFunGroupList } from "@/service/Api.js";
export default {
  props: ["id", "period", "projectNamess", "projectNames"],
  data() {
    return {
      flag: true,
      type: 0,
      groupsList: [], //职能组
      fids: 0, //职能组id
      groupName: "", //职能组名称
      userName: "",
      totalHour: "",
      monthHour: "",
      allPrjHours: "",
      salary: "",
      socialInsurance: "",
      outlay: "",
      salaryLog: "", //工资
      socialInsuranceLog: "",
      outlayLog: "",
      outlayTotal: "", //财务费用总额
      dimOtherCostTotal: "", //不明确的其他费用总额
      dimOtherCost: "", //不明确的其他费用均摊
      calculateType: "",
      userId: "",
      total: "",
      totalYear: "",
      tableData: [],
      projectList: [], //项目列表
      id1: "", //接受父组件传过来的id
      projectId: "",
      projectName: "",
      projectNames1: "",
      projectNamess1: "",
      index: 0,
      pn: 1,
      ps: 10,
      category: "",
      arrPlanMsgs: [],
      arrProjects: [],
      options: [],
      checked: false,
      dialogFormPlan: false,
      title: "",
      formLabelWidth: "150px",
      content: "",
      month: "",
      otherCostList: [
        {
          name: "",
          value: "",
        },
      ],
      dimOtherCostList: [
        {
          name: "",
          value: "",
        },
      ],
      form: {
        salary: "",
        socialInsurance: "",
        outlay: "",
        salaryLog: "", //工资
        socialInsuranceLog: "",
        outlayLog: "",
        otherCostList: [
          {
            name: "",
            value: "",
          },
        ],
        dimOtherCostList: [
          {
            name: "",
            value: "",
          },
        ],
        dynamicItem: [
          //默认显示一条
          {
            otherCost: "",
          },
        ],
        rules: {
          salaryLog: [
            { required: true, message: "请输入工资金额", trigger: "blur" },
          ],
          socialInsuranceLog: [
            { required: true, message: "请输入财务费用", trigger: "blur" },
          ],
          outlayLog: [
            { required: true, message: "请输入财务费用", trigger: "blur" },
          ],
        },
      },
      projects: [],
      tab: 0,
      pickerOptions: {
        disabledDate(time) {
          console.log("time=", time);
          return time.getTime() > Date.now() - 24 * 3600 * 1000;
        },
      },
      month: "",
      gsid: "",
    };
  },
  watch: {
    dialogFormPlan() {
      this.getManHourList();
    },
  },

  created() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    this.fids = this.userInfo.fids;
    this.getdatetime();
    this.groups();
    this.projectNames1 = this.projectNames;
    this.projectNamess1 = this.projectNamess;
    // console.log(this.projectNamess1);
    this.id1 = this.id;
    this.getManHourList();
    this.getProjectList();
  },

  methods: {
    //查询
    getManHourList() {
      let data = {
        projectId: this.id1,
        fids: this.fids,
        monthTime: this.month,
      };
      projectAccounting(data).then((res) => {
        if (res.code == 0) {
          if (res.code == 0) {
            this.tableData = res.data;
            if (res.data.length != 0) {
              this.allPrjHours = res.data[0].allPrjHours;
              this.outlayTotal = res.data[0].outlayTotal;
              this.dimOtherCostTotal = res.data[0].dimOtherCostTotal;
            } else {
              this.allPrjHours = 0;
              this.outlayTotal = "";
              this.dimOtherCostTotal = "";
            }
          }
        }
      });
    },
    getProjectList() {
      let data = {
        pn: 1,
        ps: 500,
        id: this.id1,
        period: this.month,
      };
      selectProjectListByReq(data).then((res) => {
        if (res.code == 0) {
          this.projectList = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    //数组转字符串
    convertArr1(row) {
      let newArr = [];
      if (row.otherCostList && row.otherCostList.length !== 0) {
        row.otherCostList.forEach((items, index) => {
          if (items) {
            newArr.push(items.name + items.value + "元");
          }
        });
        return newArr.join("、");
      } else {
        return (newArr = ["-"]);
      }
    },
    convertArr2(row) {
      if (row.dimOtherCost != null) {
        let dimOtherCosts = row.dimOtherCost + "元";
        return dimOtherCosts;
      } else {
        let dimOtherCosts = "-";
        return dimOtherCosts;
      }
    },

    // 限制只能在输入框中输入小数点后两位
    inputnum1() {
      this.form.salary = this.form.salary.replace(
        /^(\-)*(\d+)\.(\d\d).*$/,
        "$1$2.$3"
      );
      this.form.salaryLog = this.form.salaryLog
        .toString()
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
    },
    inputnum2() {
      this.form.socialInsurance = this.form.socialInsurance.replace(
        /^(\-)*(\d+)\.(\d\d).*$/,
        "$1$2.$3"
      );
      this.form.socialInsuranceLog = this.form.socialInsuranceLog
        .toString()
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
    },
    inputnum3() {
      this.form.outlay = this.form.outlay.replace(
        /^(\-)*(\d+)\.(\d\d).*$/,
        "$1$2.$3"
      );
      this.form.outlayLog = this.form.outlayLog
        .toString()
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
    },

    inputBlur(val, index) {
      this.form.otherCostList[index].value = val
        .replace(/[^\d.]/g, "")
        .replace(/\.{2,}/g, ".")
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".")
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
        .replace(/^\./g, "");
    },
    inputBlur2(val, index) {
      this.form.dimOtherCostList[index].value = val
        .replace(/[^\d.]/g, "")
        .replace(/\.{2,}/g, ".")
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".")
        .replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
        .replace(/^\./g, "");
    },
    changeMonth() {
      this.getManHourList();
      this.getProjectList();
    },
    getdatetime() {
      // let date = new Date();
      // let year = date.getFullYear();
      // let month = date.getMonth() + 1;
      // month = month < 10 ? '0' + month : month
      // this.month = year + '-' + month;

      this.month = this.period;
    },
    //获取职能组列表
    groups() {
      let userInfo = sessionStorage.getItem("userInfo");
      let id = JSON.parse(userInfo).id;
      selectFunGroupList().then((res) => {
        if (res.code == 0) {
          this.groupsList = res.data;
          let f;
          let arr = [];
          res.data.forEach((item) => {
            arr.push(item.id);
            f = arr.join(",");
          });
          let list = [
            {
              id: f,
              name: "所有职能组",
            },
          ];
          list.push(...res.data);
          this.groupsList = list;
          this.groupsList.forEach((item) => {
            if (item.id == this.fid) {
              this.groupName = item.name;
            }
          });
          if (res.data.length > 0) {
            let userInfo = sessionStorage.getItem("userInfo");
            if (JSON.parse(userInfo).fids == 0) {
              this.fids = f;
            } else {
              this.fids = JSON.parse(userInfo).fids;
            }
            this.islead = JSON.parse(userInfo).isLeader;
          }
        }
      });
    },
    changeGroup() {
      // console.log("职能组id", val);
      // this.fids = val;
      this.getManHourList();
    },
    changeProject(val) {
      this.id1 = val.id;
      this.getManHourList();
      this.projectNamess1 = val.name;
      this.projectNames1 = val.fullName;
    },
    select() {
      this.getManHourList();
    },
    //input回车
    inputChange() {
      let data = {
        projectId: this.id1,
        fids: this.fids,
        monthTime: this.month,
        outlayTotal: this.outlayTotal,
        dimOtherCostTotal: this.dimOtherCostTotal,
      };
      projectWholeCount(data).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data;
        }
      });
    },
    // 列求和
    getSummaries(param) {
      const { columns, data } = param; // 这里可以看出，自定义函数会传入每一列，以及数据
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        } else if (index === 10) {
          // inde=== 10的列进行求和
          // 页面分别统计 处理
          const values = data.map((item) => item[column.property]);
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = curr;
              if (!isNaN(value)) {
                return parseFloat((prev + curr).toFixed(2));
              } else {
                return prev;
              }
            }, 0);
            // 此处结合了方式一的判断处理，实现多种条件处理
            // 此处的column.property获取的值对应<el-table-column>中prop对应的字段
            switch (column.property) {
              case "total":
                return (sums[index] = sums[index]);
                break;
            }
          }
        } else if (index === 11) {
          // inde=== 11的列进行求和
          // 页面分别统计 处理
          const values = data.map((item) => item[column.property]);
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = curr;
              if (!isNaN(value)) {
                return parseFloat((prev + curr).toFixed(2));
              } else {
                return prev;
              }
            }, 0);
            // 此处结合了方式一的判断处理，实现多种条件处理
            // 此处的column.property获取的值对应<el-table-column>中prop对应的字段
            switch (column.property) {
              case "totalYear":
                return (sums[index] = sums[index]);
                break;
            }
          }
        }
      });
      return sums; // 最后返回合计行的数据
    },
    //打开添加费用接口
    addFee(row) {
      this.category = "add";
      this.title = "添加费用";
      this.userId = row.userId;
      this.projectId = row.projectId;
      this.userName = row.userName;
      this.monthHour = row.monthHour;
      this.totalHour = row.totalHour;
      this.allPrjHours = row.allPrjHours;
      this.monthTime = row.monthTime;
      this.salaryLog = "";
      this.socialInsuranceLog = "row.socialInsurance";
      this.form.otherCostList = [
        {
          name: "",
          value: "",
        },
      ];
      this.form.dimOtherCostList = [
        {
          name: "",
          value: "",
        },
      ];
      this.outlayLog = "";
      this.dialogFormPlan = true;
      this.calculateType = 1;
      // 默认清除校验
      this.$nextTick(() => {
        this.$refs["acctForm"].clearValidate();
      });
    },

    cancel() {
      this.paId = "";
      this.form.salary = "";
      this.form.socialInsurance = "";
      this.form.outlay = "";
      if ((this.category = "update")) {
        this.otherCostList = [{ name: "", value: "" }];
        this.dimOtherCostList = [{ name: "", value: "" }];
      } else {
        this.form.otherCostList = [{ name: "", value: "" }];
        this.form.dimOtherCostList = [{ name: "", value: "" }];
      }
      // 默认清除校验
      this.$nextTick(() => {
        this.$refs["acctForm"].clearValidate();
      });
      this.dialogFormPlan = false;
      // this.getManHourList();
    },

    // cancel2() {
    //     this.paId = "";
    //     this.form.salary = "";
    //     this.form.socialInsurance = "";
    //     this.form.outlay = "";
    //     this.otherCostList = [{ name: '', value: '' }];
    //     this.dimOtherCostList = [{ name: '', value: '' }];
    //     // 默认清除校验
    //     this.$nextTick(() => {
    //         this.$refs["acctsForm"].clearValidate();
    //     });
    //     this.dialogFormPlan = false;
    // },
    historyGo() {
      this.$emit("goProject", { falg: 47 });
    },
    //打开编辑窗口
    upDateFee(row) {
      this.category = "update";
      this.title = "编辑费用";
      this.gsid = row.id;
      this.userId = row.userId;
      this.projectId = row.projectId;
      this.userName = row.userName;
      this.monthHour = row.monthHour;
      this.totalHour = row.totalHour;
      this.monthTime = row.monthTime;
      this.allPrjHours = row.allPrjHours;
      this.form.salaryLog = row.salary;
      this.form.socialInsuranceLog = row.socialInsurance;
      this.form.outlayLog = row.outlay;
      this.form.otherCostList =
        row.otherCostList == null
          ? [
              {
                name: "",
                value: "",
              },
            ]
          : row.otherCostList;
      this.form.dimOtherCostList =
        row.dimOtherCostList == null
          ? [
              {
                name: "",
                value: "",
              },
            ]
          : row.dimOtherCostList;
      this.calculateType = 1;
      this.dialogFormPlan = true;
      // 默认清除校验
      this.$nextTick(() => {
        this.$refs["acctForm"].clearValidate();
      });
    },
    //新增
    submit(acctForm) {
      this.$refs[acctForm].validate((valid) => {
        if (valid) {
          let data = {
            projectId: this.id1,
            userId: this.userId,
            userName: this.userName,
            monthHour: this.monthHour,
            totalHour: this.totalHour,
            salary: this.form.salary,
            socialInsurance: this.form.socialInsurance,
            // outlay: this.form.outlay,
            otherCostList: this.form.otherCostList,
            // dimOtherCostList: this.form.dimOtherCostList,
            monthTime: this.month,
            calculateType: this.calculateType,
            allPrjHours: this.allPrjHours,
            outlayTotal: this.outlayTotal,
            dimOtherCostTotal: this.dimOtherCostTotal,
          };
          saveCostInfo(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                message: "添加成功!",
                type: "success",
              });
            }
            this.cancel();
            // this.select();
          });
        }
      });
    },
    //编辑
    submitUpdate(acctsForm) {
      this.$refs[acctsForm].validate((valid) => {
        if (valid) {
          let data = {
            id: this.gsid,
            projectId: this.id1,
            userId: this.userId,
            userName: this.userName,
            monthHour: this.monthHour,
            totalHour: this.totalHour,
            salary: this.form.salaryLog,
            socialInsurance: this.form.socialInsuranceLog,
            // outlay: this.form.outlayLog,
            otherCostList: this.form.otherCostList,
            // dimOtherCostList: this.form.dimOtherCostList,
            monthTime: this.month,
            calculateType: this.calculateType,
            allPrjHours: this.allPrjHours,
            outlayTotal: this.outlayTotal,
            dimOtherCostTotal: this.dimOtherCostTotal,
          };
          updateCostInfo(data).then((res) => {
            if (res.code == 0) {
              this.$message({
                message: "编辑成功!",
                type: "success",
              });
            }
            this.cancel();
            // this.select();
          });
        }
      });
    },
    exportExcel() {
      let data = {
        projectId: this.id1,
        fids: this.fids,
        monthTime: this.month,
      };
      exportEmpInfo(data).then((res) => {
        let blob = new Blob([res], {
          // type: "application/vnd.ms-excel;charset=UTF-8",
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
        });
        let url = window.URL.createObjectURL(blob);
        const link = document.createElement("a"); // 创建a标签
        link.setAttribute("download", new Date().getTime() + ".xlsx");
        document.body.appendChild(link);
        link.download = "项目核算表";
        link.href = url;
        link.click();
        URL.revokeObjectURL(url); // 释放内存
      });
    },
    //删除输入框
    dele1(item) {
      var index = this.form.otherCostList.indexOf(item);
      if (index !== -1) {
        this.form.otherCostList.splice(index, 1);
      }
    },
    dele2(item) {
      var index = this.form.dimOtherCostList.indexOf(item);
      if (index !== -1) {
        this.form.dimOtherCostList.splice(index, 1);
      }
    },
    // dele3(item) {
    //     var index = this.otherCostList.indexOf(item)
    //     if (index !== -1) {
    //         this.otherCostList.splice(index, 1)
    //     }
    // },
    // dele4(item) {
    //     var index = this.dimOtherCostList.indexOf(item)
    //     if (index !== -1) {
    //         this.dimOtherCostList.splice(index, 1)
    //     }
    // },
    //新增输入框
    add1() {
      this.form.otherCostList.push({
        name: "",
        value: "",
      });
    },
    add2() {
      this.form.dimOtherCostList.push({
        name: "",
        value: "",
      });
    },
    // add3() {
    //     this.otherCostList.push({
    //         name: '',
    //         value: ''
    //     });
    // },
    // add4() {
    //     this.dimOtherCostList.push({
    //         name: '',
    //         value: ''
    //     });
    // }
  },
};
</script>

<!-- <style>
.btn-input {
    line-height: 60px;
    text-align: center;
    width: 500px;
}

.dialog-footer {
    text-align: center;
}

.exit {
    float: right;
}

.navigation {
    padding: 10px;
    margin: 0;
    
}
.xiangmu {
    cursor: pointer;  /*鼠标悬停变小手*/
}

.el-select-dropdown__item.selected {
    color: #606266;
}
</style> -->
<style lang="scss" scoped>
.btn-input {
  line-height: 60px;
  text-align: center;
  width: 500px;
}

.dialog-footer {
  text-align: center;
}

.exit {
  float: right;
}

.navigation {
  padding: 10px;
  margin: 0;
}
.xiangmu {
  cursor: pointer; /*鼠标悬停变小手*/
}

.el-select-dropdown__item.selected {
  color: #606266;
}
.buttonCl {
  font-size: 16px;
  background-color: white;
  border: 0;
}

.allPrjHours {
  font-size: 16px;
  margin-bottom: 20px;
  display: inline-block;
}

.outlayTotal {
  width: 20%;
  font-size: 16px;
  margin-left: 20px;
  display: inline-block;
}

.dimOtherCostTotal {
  width: 20%;
  font-size: 16px;
  display: inline-block;
}
</style>
